<template>
    <div class="wrap">
        <part-doc-material-info :part-material-data="partMaterialData" :currentPartDocInfo="currentPartDocInfo">
            <template #cancelButton>
                <el-button type="primary" size="small"
                           @click="cancel">{{ $t('message.common.cancel') }}
                </el-button>
            </template>
        </part-doc-material-info>
    </div>
</template>

<script>
import {materialSettingCommand} from "../../../../command/MaterialSettingCommand";
import dialogMixin from "../../DialogMixin";
import PartDocMaterialInfo from "./PartDocMaterialInfo.vue";

export default {
    name: "PartDocMaterialSetting",
    mixins: [dialogMixin],
    components: {PartDocMaterialInfo},
    data() {
        return {
            isInit: false,
            dialogVisible: false,
            currentPartDocInfo: {},
            partMaterialData: [],
            selectedRowData: [],//从当前零件已经添加的材料项选择数据
            selectedAddItems: [],//选择的需要添加的材料项
        }
    },
    mounted() {
        if (!this.isInit) {
            materialSettingCommand.init(1042, 1042, 1000, () => {
                materialSettingCommand.clearAllHighLight();
                this.getCurrentPartDocInfo();
                this.isInit = true;
            })
        }
    },
    methods: {
        changePluginContainerHeight() {
            materialSettingCommand.changePluginContainerHeight({
                minWidth: this.$el.clientWidth,
                maxHeight: this.$el.clientHeight + 5,
                width: 1042
            })
        },
        cancel() {
            materialSettingCommand.closeActiveCmd();
        },
        getCurrentPartDocInfo() {
            materialSettingCommand.getCurrentDocInfo(res => {
                let document = res ?? "";
                if (document !== "") {
                    this.currentPartDocInfo = {};
                    this.currentPartDocInfo = {
                        protoRefDocId: document.id,
                        protoRefName: document.name,
                        protoRefType: document.type,
                    };
                    this.getPartMaterialData(document.id);
                }
            })
        },
        //获取当前零件绑定的材料数据
        getPartMaterialData(pid) {
            materialSettingCommand.getCurrentPartMaterialInfo(pid, res => {
                this.partMaterialData = res;
            });
        },
    },
}
</script>

<style scoped>

.wrap {
    font-size: 12px;
}

.button-style {
    display: flex;
    justify-content: flex-end;
    margin-top: 5px;
}

.label-style {
    font-size: 12px;
    color: #606266;
    line-height: 30px;
}
</style>